﻿@model PagedList<YiYiTong.Rocket.Model.ParamModel.UserBusinessMsg>
@{
    ViewBag.Title = "业务消息";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";

    BusinessMsgQueryModel paramModel = new BusinessMsgQueryModel();
    if (ViewBag.paramModel != null)
    {
        paramModel = (BusinessMsgQueryModel)ViewBag.paramModel;
    }
}
<style>
    .div_msg_notread {
        font-weight:bold;
        
    }
</style>
<form id="S_Form" class="form-inline definewidth m20" action="@Url.Action("MsgList", "BusinessMsg")" method="get">
    <div class="form_query">
        <div>
            已读未读：
            <select id="isread" name="isread">
                <option value="-10" @(paramModel.isread == -10 ? "selected" : "")>全部消息</option>
                <option value="0" @(paramModel.isread == 0 ? "selected" : "")>未读消息</option>
                <option value="1" @(paramModel.isread == 1 ? "selected" : "")>已读消息</option>
            </select>&nbsp;
        </div>
        <div>
            @{Html.RenderPartial(Url.Content("~/Views/Common/PageSize.cshtml"), paramModel);}
        </div>
        <div>
            <button type="submit" class="btn btn-primary">查询</button>
        </div>
    </div>
</form>
<table class="table table-bordered table-hover definewidth m10">
    <thead>
        <tr>
            <th style="width:40px"><input type="checkbox" name="chkall" id="chkall" />全选</th>
            <th>标题内容</th>
            <th style="width:150px">发送时间</th>
            <th style="width:200px">类型</th>
        </tr>
    </thead>
    @if (Model != null && Model.Count != 0)
    {
        int index = 0;
        foreach (var m in Model)
        {
            <tr class="@HtmlPagerHelper.TrClass(index++)">
                <td>
                    <input type="checkbox" name="cbx_last" value="@m.aDZ_BusinessMsg_SysUser.Id" />@m.aDZ_BusinessMsg_SysUser.Id
                </td>
                <td>
                    @if (m.aDZ_BusinessMsg_SysUser.IsRead == 0)
                    {
                        <div class="div_msg_notread" onclick="readonemsg(@m.aDZ_BusinessMsg_SysUser.Id)">
                            @if (!string.IsNullOrWhiteSpace(m.aDZ_BusinessMsg.msg_title))
                            {
                                @m.aDZ_BusinessMsg.msg_title <br />
                            }
                            @m.aDZ_BusinessMsg.msg   
                        </div>
                    }
                    else
                    {
                        if (!string.IsNullOrWhiteSpace(m.aDZ_BusinessMsg.msg_title))
                        {
                            @m.aDZ_BusinessMsg.msg_title <br />
                        }
                        @m.aDZ_BusinessMsg.msg
                    }
                </td>
                <td>@m.aDZ_BusinessMsg.create_time.ToString(1)</td>
                <td>@m.aDZ_BusinessMsg.BusinessMsgName</td>
            </tr>
        }
    }
    <tr>
        <td colspan="20">
            <a href="javascript:void(0);" onclick="delmsg()">删除</a>
            <a href="javascript:void(0);" onclick="readmsg()">标记为已读</a>
            <a href="javascript:void(0);" onclick="readallmsg()">全部已读</a>
        </td>
    </tr>
</table>
<div class="inline pull-right page">
    @if (Model != null)
    {
        @Html.Pager(Model, HtmlPagerHelper.BasePagerOption)
    }
</div>
<script>
    reloadHandler = function () {
        window.location.reload();
    }
    function delmsg(id) {
        var ids = getCheckboxList();
        if (ids.length == 0) {
            BUI.Message.Alert("请选择要删除的数据", 'warning');
            return;
        }

        BUI.Message.Show({
            title: '提示',
            msg: '确定要删除选择的记录吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("delmsg", "BusinessMsg")";
                      parameter = { ids: ids };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
              },
              {
                  text: '取消',
                  elCls: 'button',
                  handler: function () {
                      this.close();
                  }
              }

            ]
        });
    }
    function readallmsg() {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要将所有的消息都已读吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("readallmsg", "BusinessMsg")";
                      parameter = { };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
              },
              {
                  text: '取消',
                  elCls: 'button',
                  handler: function () {
                      this.close();
                  }
              }

            ]
        });
    }
    function readmsg() {
        var ids = getCheckboxList();
        if (ids.length == 0) {
            BUI.Message.Alert("请选择要设置已读的数据", 'warning');
            return;
        }

        BUI.Message.Show({
            title: '提示',
            msg: '确定要将选择的消息都已读吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("readmsg", "BusinessMsg")";
                      parameter = { ids: ids };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
              },
              {
                  text: '取消',
                  elCls: 'button',
                  handler: function () {
                      this.close();
                  }
              }

            ]
        });
    }
    function readonemsg(id) {
        url = "@Url.Action("readmsg", "BusinessMsg")";
        parameter = { ids: id };
        $.post(url, parameter, function (result) {
            reloadHandler();
            //ShowActionResult(result, reloadHandler);
        });
    }
</script>